<%@page import="java.text.DecimalFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML>
<html>
  <head>
    
    <title>订单结算</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<link href="/shop/css/shop-top.css" rel="stylesheet" />
	<link href="/shop/css/shop-footer.css" rel="stylesheet" />
	<link href="/shop/css/shop-common.css" rel="stylesheet" />
	
	<jsp:include page="/head.jsp" />
	<script type="text/javascript" src="/shop/js/shop-public.js"></script>
	<script type="text/javascript" src="/shop/js/shop-jquery-1.5.1.js"></script>

  </head>
  
  <body>
    <!-- 工具条 --> 
  <!-- 顶部工具条 --> 
  <c:import url="/news-class.do?mb=header" /> 
  <div class="top"> 
   <%@ include file="/shop/jsps/top.jsp"  %>
  </div>
  <script type="text/javascript">
//头部topbar会员中心显示与隐藏
var Account= document.getElementById('account');
            var Downmenu= document.getElementById('dbox');
            var timer = null;//定义定时器变量
            //鼠标移入div1或div2都把定时器关闭了，不让他消失
            Account.onmouseover = Downmenu.onmouseover = function ()
            {
				 //改变箭头方向
				$("i#icount").attr("class","fa fa-angle-up");
               
				 //改变背景颜色
				 Account.style.backgroundColor = '#fff';
				 //显示下拉框
                $("#dbox").show();
				//关闭定时执行
                clearTimeout(timer);
            }
			
            //鼠标移出div1或div2都重新开定时器，让他延时消失
            Account.onmouseout = Downmenu.onmouseout = function ()
            {
				$("i#icount").attr("class","fa fa-angle-down");
				Account.style.backgroundColor = '#F5F5F5';
				 //开定时器，每隔200微妙下拉框消失
                timer = setTimeout(function () { 
                    $("#dbox").hide(); }, 200);
            }
       
		
		</script> 
  <!-- 顶部工具条 结束 --> 
  <!-- /工具条 --> 
  <!-- 头部 --> 
  <div class="wrapper-address"> 
   <!-- 导航条 --> 
   <div class="header-wrap">
    <a href="#" class="logo" title="键盘侠商城"><img
				src="images/logo.png" alt=""></a> 
    <div class="shopping_cart_procedure2">
     <span>1、我的购物车</span>
     <span> 2、填写订单</span>
     <span style="width:175px; padding:0;">3、完成订单</span> 
    </div> 
   </div> 
   <!-- /头部 --> 
   <!-- 主体 --> 
   <div class="wrapper-order"> 
    <div id="check"> 
     <div class="mt"> 
      <h2>填写并核对订单信息</h2> 
     </div> 
     <script type="text/javascript">
     

$(document).ready(function(){
  $("#show").click(function(){
  $("#formsender").toggle();

  });
});
function savemsg() { 
//判断是否是默认地址 
if (document.getElementById("isdefault").checked==true) {
       var info="1"; //是默认
    }
    else {
      var info="0"; //不是默认
    }
    var userName = "${username }";
    var pca=$("#idprovince").val()+$("#idcity").val()+$("#idarea").val();
	var address=$("#address").val();
	var orderid=$("#orderid").val();
	var username=$("#realname").val();
	var phone=$("#phone").val();
	var b=$("#youbian").val();
	
	$.ajax({
type:'post', //传送的方式,get/post
url:'add.address', //发送数据的地址
data:{province:$("#idprovince").val(),city:$("#idcity").val(),area:$("#idarea").val(),posi:address,pho:phone,rel:username,userName:userName,msg:info},
 dataType: "json",
success:function(data)
{
	if(data.success){
		if(info==1){
			var str='<p><input checked="checked" type="radio" name="sender" value="'+data.AddressId+'" id="default" />&nbsp;&nbsp;收件人：'+username+'&nbsp;&nbsp;&nbsp;联系电话：'+phone+'&nbsp;'+'&nbsp;&nbsp;&nbsp;收货地址：'+pca+address+'</p>';
			$("#senderdetail").append(str);
			$("#formsender").toggle(); //隐藏添加地址div
		}else{
			var str='<p><input type="radio" name="sender" value="'+data.AddressId+'" id="default" />&nbsp;&nbsp;收件人：'+username+'&nbsp;&nbsp;&nbsp;联系电话：'+phone+'&nbsp;'+'&nbsp;&nbsp;&nbsp;收货地址：'+pca+address+'</p>';
			$("#senderdetail").append(str);
			$("#formsender").toggle(); //隐藏添加地址div
		}
		
	}
},
error:function (event, XMLHttpRequest, ajaxOptions, thrownError) {
alert("表单错误，"+XMLHttpRequest+thrownError); }
		})
	 }
function makeorder() {
	  //给隐藏属性赋值  提交表单
  	  document.getElementById("senderid").value=getvv();
	  document.myform.submit();     
		 }
function getvv(){
	//获取单选的值
	var group = document.getElementsByName('sender');

	for(var i = 0; i< group.length; i++){
	if(group[i].checked){
	return group[i].value;
	}}
}
</script> 
     <div class="orderplace"> 
      <link type="text/css" href="css/selectpick.css" rel="stylesheet" /> 
      <div class="o_title"> 
       <h2>收货人信息 </h2> 
      </div> 
      <div id="formwarp" class="place"> 
       <div id="senderdetail"> 
       <c:forEach items="${addressList }" var="ord">
       	<p>
       	<c:if test="${ord.shopAddressMsg==1 }">
       		<input type="radio" checked="checked" id="default" name="sender" value="${ord.shopAddressId }" />&nbsp;收件人：${ord.shopAddressRealName }&nbsp;&nbsp;联系电话:${ord.shopAddressUserTel }&nbsp;&nbsp;收货地址：${ord.shopAddressProvince }${ord.shopAddressCity }${ord.shopAddressArea }${ord.shopAddressUserAddress} 
       	</c:if>
       	<c:if test="${ord.shopAddressMsg!=1 }">
       		<input type="radio" id="default" name="sender" value="${ord.shopAddressId }" />&nbsp;收件人：${ord.shopAddressRealName }&nbsp;&nbsp;联系电话:${ord.shopAddressUserTel }&nbsp;&nbsp;收货地址：${ord.shopAddressProvince }${ord.shopAddressCity }${ord.shopAddressArea }${ord.shopAddressUserAddress} 
       	</c:if>
       	</p> 
       </c:forEach>
       </div> 
       <script type="text/javascript" src="/shop/js/shop-city.js"></script>  
      </div> 
     </div> 
     <!--收货信息 结束--> 
     <!--订单支付 开始--> 
     <form action="zhifubao.s" method="post" name="myform" id="myform"> 
      <div class="orderplace"> 
       <div class="o_title"> 
       </div> 
       <div id="formwarp"> 
        <dl> 
         <dt>
          支付方式：(暂只支持在线支付)
         </dt> 
         <dd> 
          <input type="radio" name="PayType" id="pay" checked="checked" value="2" />在线支付 
         </dd> 
        </dl> 
       </div> 
      </div> 
      <!--订单支付 结束--> 
      <!--商品信息 开始--> 
      <div class="orderplace"> 
       <div class="o_title"> 
        <h2>商品信息</h2>
       </div> 
       <table border="0" cellspacing="0" cellpadding="0" class="gridtable cart-2" width="100%"> 
        <tbody>
         <tr class="com_list_tit"> 
          <th>商品名称</th> 
          <th>单价(元)</th> 
          <th>数量</th> 
         </tr> 
         <c:if test="${product!=null}">
         <c:forEach items="${product }" var="pro">
         	<tr> 
	          <td align="center"><input type="hidden" class="pid" value="${pro.shopCartProductId }"/><a href="shopgoods-1.do?productId=${pro.shopCartProductId }" class="goodsnames" target="_blank">${pro.shopCartGoodsName}</a></td> 
	          <td align="center" id="dan">${pro.shopCartProductPrice}</td> 
	          <td align="center" class="numb" id="shu">${pro.shopCartNum}</td>
	        </tr>
         </c:forEach>
         </c:if>
         
         <c:if test="${products!=null}">
         	<tr> 
	          <td align="center"><input type="hidden" class="pid" value="${products.productId }"/><a href="shopgoods-1.do?productId=${products.productId }" class="goodsnames" target="_blank">${products.productName}</a></td> 
	          <td align="center" id="dan">${products.productPrice1}</td> 
	          <td align="center" class="numb" id="shu">${num}</td>
	        </tr>
         </c:if>
         
         <c:if test="${order!=null}">
         	<tr> 
	          <td align="center"><input type="hidden" class="pid" value="${order.shopOrderItemProductId }"/><a href="shopgoods-1.do?productId=${order.shopOrderItemProductId }" class="goodsnames" target="_blank">${order.shopOrderItemProductName}</a></td> 
	          <td align="center" id="dan">${order.shopOrderItemProductPrice}</td> 
	          <td align="center" class="numb" id="shu">${order.shopOrderItemNum}</td>
	        </tr>
         </c:if>
		 <!-- 订单商品循环go -->
          
		 <!-- 订单商品循环end -->
        </tbody>
       </table> 
      </div> 
      <!--商品信息 结束--> 
      <!--发票信息 开始--> 
      <div class="orderplace fapiao"> 
       <h2> 留言信息</h2> 
       <textarea name="liuyan" id="ss" rows="4" cols="60"></textarea>
      </div> 
      <!--发票信息 结束--> 
      <!--提交信息 开始--> 
      <c:if test="${order.shopOrderId==null}">
      <div class="orderplace trans"><!-- onclick="document:zfb.submit()" -->
       <p class="jiesuan">应付总额 <span id="TotalNeedPay" class="red">${total}</span>元 <a class="btn_submit_pay" href="javascript:void(0)" onclick="checklogin();return false;">提交订单</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p> 
       <!--提交信息 结束--> 
      </div>
      </c:if>
      <c:if test="${order.shopOrderId!=null}">
      <div class="orderplace trans"><!-- onclick="document:zfb.submit()" -->
       <p class="jiesuan">应付总额 <span id="TotalNeedPay" class="red">${total}</span>元 <a class="btn_submit_pay" href="javascript:void(0)" onclick="checklogin();return false;">提交订单</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p> 
       <!--提交信息 结束--> 
      </div>
      </c:if>
     </form> 
    </div> 
    <!-- /主体 --> 
   </div>
  </div> 
  <%@ include file="jsps/footer.jsp" %> 
  <!-- /底部 --> 
 	<script type="text/javascript">

 	function checklogin() {
		var cartItemIdArray = $(":radio[name=sender][checked=true]").val();//获取地址编号
		$("#dizhi").val(cartItemIdArray);

		var liuyans=$("#ss").val();//获取留言
		$("#liuyanxx").val(liuyans);
		
		var cartItemId = new Array();
		$(".goodsnames").each(function() {
			cartItemId.push($(this).text());//把复选框的值添加到数组中
		});
		$("#goodsname").val(cartItemId.toString());

		var proid = new Array();
		$(".pid").each(function() {
			proid.push($(this).val());//把复选框的值添加到数组中
		});	
		$("#shangpID").val(proid.toString());
		
		var number = new Array();
		$(".numb").each(function() {
			number.push($(this).text());//把复选框的值添加到数组中
		});	
		$("#bianhao").val(number.toString());
		$("#ddxx").submit();
		}
	</script>
  	<form action="zhifubao.do" method="post" name="ddxx" id="ddxx"> 
  		<input type="hidden" id="dizhi" name="dizhi" value=""/><!--收货地址编号-->
  		<input type="hidden" id="price" name="price" value="${total}"/><!--结算总价  -->
  		<input type="hidden" id="goodsname" name="goodsname" value=""/><!--名字数组  -->
  		<input type="hidden" id="liuyanxx" name="liuyanxx" value=""/><!--备注-->
  		<input type="hidden" id="shangpID" name="shangpID" value=""/><!-- 商品iD -->
  		<input type="hidden" id="bianhao" name="bianhao" value=""/><!-- 数量 -->
  		<input type="hidden" id="orderid" name="orderid" value="${order.shopOrderId}"/>
  		<input type="hidden" id="dindanId" name="dindanId" value="${order.shopOrderItemId}"/><!-- 订单排序唯一编号 -->
 	 </form>
  </body>
</html>
